package com.wuyou.single.common.security.service.impl;

import com.wuyou.single.common.api.IErrorCode;
import com.wuyou.single.common.api.ResultCode;
import com.wuyou.single.common.exception.UserException;
import com.wuyou.single.common.security.service.JwtService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * Token service impl
 */
@Service
public class JwtServiceImpl implements JwtService {

    @Override
    public String checkToken(HttpServletRequest request) {
        String token = (String) request.getAttribute(jwtUtil.getTokenHead());
        if (StringUtils.isBlank(token)) {
            throw new UserException(ResultCode.UNAUTHORIZED);
        }
        String userName = jwtUtil.getUserNameFromToken(token);
//        jwtUtil.validateToken(token,)
        return token;
    }

    @Override
    public boolean isSysSign(String token) {
        return true;
    }

    @Override
    public void expired(String token) {

    }

    @Override
    public void renewExpired(String token) {

    }
}
